﻿using System;
using System.Collections.Specialized;

namespace vCrossPost.PingFM
{
    public enum PostMethods
    {
        Default,
        Blog,
        MicroBlog,
        Status,
    }

    public struct PostMessage
    {
        public string Body;
        public string Excludes;
        public string Location;
        public string Media;
        public PostMethods Method;
        public string Service;
        public string Title;
        public bool Debug;

        public string MethodString
        {
            get
            {
                switch (Method)
                {
                    case PostMethods.Blog:
                        return "blog";

                    case PostMethods.MicroBlog:
                        return "microblog";

                    case PostMethods.Status:
                        return "status";

                    default:
                        return "default";
                }
            }
        }

        public void CopyTo(NameValueCollection values)
        {
            if (values == null) throw new ArgumentNullException("values");

            if (string.IsNullOrEmpty(Body))
                throw new InvalidOperationException("Body cannot be null or empty.");

            if (Method == PostMethods.Blog && string.IsNullOrEmpty(Title))
                throw new InvalidOperationException("Title is required for Blog method");

            values["post_method"] = MethodString;
            values["body"] = Serialization.Base64Encode(Body);
            values["encoding"] = "base64";

            if (!string.IsNullOrEmpty(Title))
                values["title"] = Serialization.Base64Encode(Title);

            if (!string.IsNullOrEmpty(Location))
                values["location"] = Serialization.Base64Encode(Location);

            if (!string.IsNullOrEmpty(Media))
                values["media"] = Serialization.Base64Encode(Media);

            if (!string.IsNullOrEmpty(Service))
                values["service"] = Service;

            if (!string.IsNullOrEmpty(Excludes))
                values["exclude"] = Excludes;

            if (Debug)
                values["debug"] = "1";
        }
    }
}